package com.example.hasee.zhcd.Util;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;


import com.example.hasee.zhcd.Activities.LoginActivity;
import com.example.hasee.zhcd.Activities.MainActivity;

import java.util.HashMap;


public class GlobalParameter {
    public static HashMap<String, Object> gHashmap = new HashMap<String, Object>();
    private static Bundle gBundle = new Bundle();

    /**
     * @param key
     * @param value
     */
    public static void JumpFrontPage(Context context) {
        Intent intent = new Intent(context, MainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK
                | Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

    public static void JumpLoginPage(Context context) {
        Intent intent = new Intent(context, LoginActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK
                | Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }


    public static void put(String key, Object value) {
        if (gHashmap == null) {
            gHashmap = new HashMap<String, Object>();
        }
        gHashmap.put(key, value);
    }

    /**
     * @param key
     * @return
     */
    public static Object get(String key) {
        if (gHashmap != null) {
            return gHashmap.get(key);
        }
        return null;
    }

    /**
     * 清除指定key的Object
     *
     * @param key
     */
    public static void remove(String key) {
        if (gHashmap != null) {
            gHashmap.remove(key);
        }
    }

    /**
     * 清空Hashamp
     *
     * @param key
     */
    public static void clearAll() {
        if (gHashmap != null) {
            gHashmap.clear();
        }
        if (gBundle != null) {
            gBundle.clear();
        }
    }

    /**
     * Inserts a String value into the mapping of this Bundle, replacing any
     * existing value for the given key. Either key or value may be null.
     *
     * @param key   a String, or null
     * @param value a String, or null
     */
    public static void putString(String key, String value) {
        gBundle.putString(key, value);
    }

    /**
     * Inserts a CharSequence value into the mapping of this Bundle, replacing
     * any existing value for the given key. Either key or value may be null.
     *
     * @param key   a String, or null
     * @param value a CharSequence, or null
     */
    public static void putCharSequence(String key, CharSequence value) {
        gBundle.putCharSequence(key, value);
    }

    public static String getString(String key) {
        return gBundle.getString(key);
    }

    /**
     * 设置Boolean 参数
     *
     * @param key
     * @param value
     */
    public static void putboolean(String key, boolean value) {
        gBundle.putBoolean(key, value);
    }

    public static boolean getBoolean(String key) {
        return gBundle.getBoolean(key);
    }

    public static CharSequence getCharSequence(String key) {
        return gBundle.getCharSequence(key);
    }

    public static void putFloat(String key, float value) {
        gBundle.putFloat(key, value);
    }

    public static float getFloat(String key) {
        return gBundle.getFloat(key);
    }
}
